package top.doe.hive.localtest;

import org.apache.hadoop.hive.ql.exec.UDAF;
import org.apache.hadoop.hive.ql.exec.UDAFEvaluator;
import org.apache.hadoop.io.BytesWritable;
import org.roaringbitmap.RoaringBitmap;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;

public class MyCollect extends  UDAF {

    public static class MyCollectEvaluator implements UDAFEvaluator{

        ArrayList<Integer> lst;

        public MyCollectEvaluator() {
            init();
        }

        @Override
        public void init() {
            lst = new ArrayList<>();
        }

        public boolean iterate(Integer value) {
            lst.add(value);
            return true;
        }

        public ArrayList<Integer>  terminatePartial() {
            return lst;
        }


        public boolean merge(ArrayList<Integer> plst) throws IOException {

            lst.addAll(plst);

            return true;
        }

        public ArrayList<Integer> terminate() throws IOException {
            return lst;
        }

    }

}
